package com.gict.antifraudback.controller.web.common;

import com.gict.antifraudback.result.ResultEnum;
import com.gict.antifraudback.result.ResultView;
import com.gict.antifraudback.service.FilesService;
import com.gict.antifraudback.service.VideoService;
import com.gict.antifraudback.utils.NoAuthorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 公共文件上传
 */
@RestController
@RequestMapping("/wapi/common")
public class FileController {

    @Autowired
    private FilesService filesService;
    @Autowired
    private VideoService videoService;

    @PostMapping("/fileUpload")
    public ResultView uploadImage(@RequestParam("image") MultipartFile image, @RequestParam String label) {
        String url = filesService.uploadFileToOss(image, label);
        if (url != null) {
            return ResultView.ok(url);
        }
        return ResultView.error(ResultEnum.CODE_2, "上传失败！");
    }

    @PostMapping("/videoUpload")
    public ResultView videoUpload(@RequestParam("video") MultipartFile video, @RequestParam("label") String label) {
        String url = filesService.uploadFileToOss(video, label);
        if (url != null) {
            return ResultView.ok(url);
        }
        return ResultView.error(ResultEnum.CODE_2, "上传失败！");
    }

    @PostMapping("/dataRepair")
//    @NoAuthorization
    public ResultView dataRepair() {
        String url = filesService.dataRepair();
        return ResultView.ok(url);
    }
}
